package org.dromara.lessor.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.admin.domain.bo.AdvancePayRecordBo;
import org.dromara.admin.domain.vo.AdvancePayRecordVo;
import org.dromara.admin.service.IAdvancePayRecordService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出租方的垫资账单付款记录
 *
 * @author Lion Li
 * @date 2025-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lessor/advancePayRecord")
public class LessorAdvancePayRecordController extends BaseController {

    private final IAdvancePayRecordService advancePayRecordService;

    /**
     * 出租方查询名下垫资账单付款记录列表
     */
//    @SaCheckPermission("lessor:advancePayRecord:list")
    @GetMapping("/payRecordList")
    public TableDataInfo<AdvancePayRecordVo> payRecordList(AdvancePayRecordBo bo, PageQuery pageQuery) {
        Long userId = LoginHelper.getUserId();
        if (userId == null){
            throw new ServiceException("用户未登录");
        }
        return advancePayRecordService.queryPagePayRecordList(bo, pageQuery, userId);
    }

    /**
     * 导出垫资账单付款记录列表
     */
//    @SaCheckPermission("lessor:advancePayRecord:export")
    @Log(title = "垫资账单付款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AdvancePayRecordBo bo, HttpServletResponse response) {
        List<AdvancePayRecordVo> list = advancePayRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "垫资账单付款记录", AdvancePayRecordVo.class, response);
    }

    /**
     * 获取垫资账单付款记录详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("lessor:advancePayRecord:query")
    @GetMapping("/{id}")
    public R<AdvancePayRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(advancePayRecordService.queryById(id));
    }

    /**
     * 出租方审核垫资付款记录
     */
//    @SaCheckPermission("lessor:advancePayRecord:review")
    @Log(title = "垫资账单付款记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/reviewCapitalPay")
    public R<Void> reviewCapitalPay(@Validated @RequestBody AdvancePayRecordBo bo) {
        return toAjax(advancePayRecordService.reviewCapitalPay(bo));
    }
}
